package com.huadao.cart_ccs.experiment.log.paramsAnysis;

import android.os.Bundle;

import com.github.mikephil.charting.data.Entry;
import com.huadao.cart_ccs.R;
import com.huadao.cart_ccs.common.ParamsPreferences;
import com.huadao.cart_ccs.common.UtilHelpers;
import com.huadao.cart_ccs.common.deviceController.TemperatureController;
import com.huadao.cart_ccs.greendao.GreenDaoManager;
import com.huadao.cart_ccs.greendao.entity.Temperature;
import com.huadao.cart_ccs.greendao.gen.TemperatureDao;

import java.util.List;

public class TemperatureFrag extends BaseEnvironmentFrag {

    private TemperatureDao temperatureDao;

    public static TemperatureFrag getInstance(int day) {
        Bundle bundle = new Bundle();
        bundle.putInt("day", day);
        TemperatureFrag temperatureFrag = new TemperatureFrag();
        temperatureFrag.setArguments(bundle);
        return temperatureFrag;
    }

    @Override
    protected void initView() {
        temperatureDao = GreenDaoManager.getInstance().getNoCacheSession().getTemperatureDao();
    }

    @Override
    protected float getLimitValue() {
        return  TemperatureController.getInstance().getSettedValue().floatValue();
    }

    @Override
    protected int getLimitLineColor() {
        return getResources().getColor(R.color.limit_line);
    }

    @Override
    protected int getLineColor() {
        return getResources().getColor(R.color.temperature_line);
    }

    @Override
    protected void setDataSet() {
        List<Temperature> temperatureList = temperatureDao.queryBuilder().where(TemperatureDao.Properties.ProjectId.eq(projectId), TemperatureDao.Properties.StageId.eq(stageId)).orderDesc(TemperatureDao.Properties.Date).limit(8640).list();
//        for (int i = 0; i < temperatureList.size(); i++) {
//            Temperature temperature = temperatureList.get(i);
//            float x = UtilHelpers.getTime(temperature.getDate());
//            Entry entry = new Entry(x, (float) temperature.getTemperature());
//            dataSet.addEntry(entry);
//        }
        for (int i = temperatureList.size()-1; i >-1; i--) {
            Temperature temperature = temperatureList.get(i);
            float x = UtilHelpers.getTime(temperature.getDate());
            Entry entry = new Entry(x, (float) temperature.getTemperature());
//            dataSet.addEntry(entry);
            lineData.addEntry(entry,0);
        }
    }

    @Override
    protected String getLabel() {
        return getString(R.string.temperature);
    }
}
